import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 以下代码为了解决 "跳转相同路径页面报错" 的问题,重写了push方法
// 获取原型对象上的push函数
// const originalPush = Router.prototype.push
// // 修改原型对象中的push方法
// Router.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }
// const originalReplace = Router.prototype.replace
// Router.prototype.replace = function replace(location) {
//   return originalReplace.call(this, location).catch(err => err)
// }


export default new Router({
  routes: [{
      path: '/',
      name: 'Home',
      component: () => import("views/Home"),
    },
    // 报名
    {
      path: '/enroll',
      name: 'enroll',
      component: () => import('views/Enroll'),
    },
    // 关于 
    {
      path: '/about',
      name: 'about',
      component: () => import("views/About"),
      meta: {
        returnTop: true
      }
    },
    {
      path: '/home',
      name: 'Home',
      component: () => import("views/Home/index")
    },
    // 注册
    {
      path: '/register',
      name: 'register',
      component: () => import('views/Register'),
    },
    {
      path: '/article',
      name: 'article',
      component: () => import('views/Article'),
    },
    // 欢迎
    {
      path: '/welcome',
      name: 'welcome',
      component: () => import('views/Welcome'),
    },
    // 登录
    {
      path: '/login',
      name: 'login',
      component: () => import('views/Login'),
    },
    // 用户主页
    {
      path: '/account',
      name: 'account',
      redirect: '/account/personInfo',
      component: () => import('views/Account'),
      children:[
        {
          path: 'personInfo',
          name: 'personInfo',
          component: () => import('views/Account/IndexForm/index')
        },
        {
          path: 'updatePass',
          name: 'updatePass',
          component: () => import('views/Account/UpdatePass/index')
        },
      ]
    },
  ],
  // 页面刷新时，期望滚动到哪个位置
  scrollBehavior(to) {
    if (to.meta.returnTop) {
      return {
        x: 0,
        y: 0
      }
    }
  },
})
